<?php
class Control
{
    protected $template;
	protected $view;
	protected $params = array();
	protected $security = array();
	protected $mail;
	protected $mensagem;

    public function __construct()
    {
        $this->view = new View();
        $this->params = ControleURI::$params;
    }

    public function setParams($params)
    {
    	if(is_array($params))
    	{
    		foreach ($params as $key => $value)
    			$this->params[$key] = $value;
    	} else {
    		$this->params[$params] = $params;
    	}
    }

    public function getParams()
    {
    	return $this->params;
    }

    public function setLayout($layout)
    {
    	Application::setLayout($layout);
    }

    public function setTemplate($template)
    {
    	if($this->view->templateExists($template.'.php'))
    		Application::setTemplate($template);
    }

	public function redirect($local = null){
        header("Location:". $local);
        exit();
    }

    public function isSecure()
    {
    	if(!isset($_SESSION['user'])){
    		ControleURI::$module = 'login';
    		ControleURI::$control = 'ControleLogin';
    		ControleURI::$action = 'login';

    		$this->view->template_dir = APPLICATION_PATH . '/modules/'. ControleURI::getModule() .'/view/';
    	}
    }
}